package client.view;


import java.awt.Color;
import java.awt.Graphics;
import java.util.Collection;

import javax.swing.JPanel;

import client.mobile.Mobile;
import client.mobile.Player;
import client.utility.Point2d;



public class ViewPort extends JPanel{

	private static final long serialVersionUID = 1L;
	private Collection<Mobile> mobiles;
	private Player player;
	
	public ViewPort(Player p){
		super();
		this.mobiles=p.getVisibleMob();
		player=p;
		repaint();
	}

  
  	public void paint(Graphics g) {
  		double healthPercent;
  		
  		g.drawImage(ImageDatabase.getMap(player.getMap()), 0,0, this );
  		
  		for(Mobile m:mobiles){
  			healthPercent = (m.getHealth())*1.0/(m.getMaxHealth())*1.0;
  			g.setColor(Color.GREEN);
  			
  			Point2d p=m.getPosition();
  			g.fillOval(p.getX(), p.getY(), 20, 20);
  			g.drawString(m.getName(), p.getX(), p.getY()+30);
  			g.setColor(Color.YELLOW);
  			g.fillRect(p.getX()-5, p.getY()-25, (int)(healthPercent*20), 6);
  			g.setColor(Color.BLUE);
  			g.drawRect(p.getX()-5, p.getY()-25, 20, 6);
  		}

		Point2d p=player.getPosition();
  		
		g.setColor(Color.RED);
		g.fillOval(p.getX()-10, p.getY()-20, 20, 20);
		g.drawString(player.getName(), p.getX(), p.getY()-6);
		
		g.setColor(Color.YELLOW);
		
		healthPercent = (player.getHealth())*1.0/(player.getMaxHealth())*1.0;
		g.fillRect(p.getX(), p.getY()-25, (int)(healthPercent*20), 6);
		g.setColor(Color.BLUE);
		g.drawRect(p.getX(), p.getY()-25, 20, 6);
		
    }
}